<template>
  <div class="app-category">
    <h2 class="category-title">{{ title }}</h2>
    <div class="app-section">
      <div class="featured-app">
        <img :src="featured.image" :alt="featured.name" />
        <h3>{{ featured.name }}</h3>
      </div>
      <div class="app-grid">
        <div v-for="app in apps" :key="app.id" class="app-item" @click="openApp(app.url)">
          <div class="app-icon">{{ app.icon }}</div>
          <div class="app-name">{{ app.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useWebsiteStore } from '~/stores/website'
import { storeToRefs } from 'pinia'

interface Props {
  title: string
  featured: {
    name: string
    image: string
  }
  apps: Array<{
    id: number
    name: string
    icon: string
    url: string
  }>
}

const props = withDefaults(defineProps<Props>(), {
  title: '应用分类',
  featured: () => ({
    name: '特色应用',
    image: '/placeholder-image.jpg'
  }),
  apps: () => []
})

const store = useWebsiteStore()
const { apps } = storeToRefs(store)

onMounted(() => {
  store.fetchApps()
})

const openApp = (url: string) => {
  window.open(url, '_blank')
}
</script>

<style scoped>
.app-category {
  margin-bottom: 2rem;
}

.category-title {
  font-size: 1.5rem;
  color: #333;
  margin-bottom: 1rem;
  padding: 0 20px;
}

.app-section {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 2rem;
  padding: 20px;
}

.featured-app {
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.featured-app img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.featured-app h3 {
  padding: 1rem;
  margin: 0;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.app-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.app-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.app-name {
  font-size: 0.9rem;
  text-align: center;
  color: #333;
}
</style> 